import http from '../util/request.js';
import config from '../../config.js';
var app = getApp();
//引入这个插件，使html内容自动转换成wxml内容
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    userInfo:[],
    imgUrls: [],
    typelist: [],
    page: 0,
    size: 10,
    desc:'',
    tel:'',
    num:12,
      indicatorDots: false,
      autoplay: false,
      interval: 3000,
      duration: 800,
	  products:[]
  },
  load() {
    //广告列表
    http.get('api', { r:'home.Adlist'}).then(data => {
      this.setData({ imgUrls: data });
    });
    //获取分类
    http.get('api', { r: 'home.Typelist' }).then(data => {
      this.setData({ typelist: data });
      console.log(data);
    });
  },
  onLoad: function() {
      this.load();
  },
  navigator:function(e){
    wx.switchTab({
      url: e.currentTarget.dataset.url,
    })
  },
  //动画
  startNotice: function() {
    var me = this;
    var notices = me.data.notices || [];
    if( notices.length == 0 ) {
      return;
    }

    var animation = me.animation;
    //animation.translateY( -12 ).opacity( 0 ).step();
    animation.translateY( 0 ).opacity( 1 ).step( { duration: 0 });
    me.setData( { animationNotice: animation.export() });

    var noticeIdx = me.data.noticeIdx + 1;
    if( noticeIdx == notices.length ) {
      noticeIdx = 0;
    }

    // 更换数据
    setTimeout( function() {
      me.setData( {
        noticeIdx: noticeIdx
      });
    }, 400 );

    // 启动下一次动画
    setTimeout( function() {
      me.startNotice();
    }, 5000 );
  },
  onShow: function() {
    this.startNotice();

  }
})